#include <climits>
#include <iostream>
#include <vector>
using namespace std;

template <typename T>
void print(const std::vector<T>& vec) {
    for (auto v : vec) {
        std::cout << v << ", ";
    }
    std::cout << std::endl;
}

class Solution {
  public:
    vector<int> luckyNumbers(vector<vector<int>>& matrix) {
        std::vector<int> lucky;
        if (matrix.size() == 0) return lucky;
        int length = matrix.size();
        int height = matrix[0].size();
        std::vector<int> col_max;
        for (int i = 0; i < height; ++i) {
            int max = INT_MIN;
            for (int j = 0; j < length; ++j) {
                if (matrix[j][i] > max) max = matrix[j][i];
            }
            col_max.push_back(max);
        }
        print(col_max);
        for (int i = 0; i < matrix.size(); ++i) {
            int min = INT_MAX, row = -1;
            for (int j = 0; j < matrix[0].size(); ++j) {
                if (matrix[i][j] < min) min = matrix[i][j], row = j;
            }
            std::cout << min << ", " << row << '\n';
            if (min == col_max[row]) lucky.push_back(min);
        }
        print(lucky);
        return lucky;
    }
};

int main() {
    std::vector<std::vector<int>> matrix{{3, 7, 8}, {9, 11, 13}, {15, 16, 17}};
    Solution s;
    s.luckyNumbers(matrix);
    return 0;
}
